
import '../model/seach_model.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;

class SearchDao {

  static Future<SearchModel> fetch(String urlStr,String text) async{
    var url = Uri.parse(urlStr);
    final response = await http.get(url);
    if(response.statusCode == 200){
      Utf8Decoder utf8decoder = Utf8Decoder();
      final result = json.decode(utf8decoder.convert(response.bodyBytes));
      SearchModel model =  SearchModel.fromJson(result);
      model.keyword = text;
      return model;
    }else {
      throw Exception('$urlStr 接口异常');
    }

  }

}